###
# Location of INET project directory (relative to './src/' and './simulations/'):
#
INET ?= ../../inet
#
###

.PHONY: all clean cleanall makefiles checkmakefiles

all: checkmakefiles
	cd src && $(MAKE)
	cd simulations && $(MAKE)

clean: checkmakefiles
	cd src && $(MAKE) clean
	cd simulations && $(MAKE) clean

cleanall: checkmakefiles
	@cd src && $(MAKE) MODE=release clean
	@cd src && $(MAKE) MODE=debug clean
	@rm -f src/Makefile
	@cd simulations && $(MAKE) MODE=release clean
	@cd simulations && $(MAKE) MODE=debug clean
	@rm -f simulations/Makefile

###
# Command line arguments for 'opp_makemake' generated by IDE using meta flags
#   '--meta:use-exported-include-paths'
#   '--meta:use-exported-libs'
# for correct resolution of INET dependencies (cf. '.oppbuildspec'):
#
MAKEMAKE_OPTIONS = -f --deep -o nesting -O out -KINET_PROJ=$(INET) -DINET_IMPORT -I'$$(INET_PROJ)/src' -L'$$(INET_PROJ)/src' -l'INET$$(D)' -I.
#
###

makefiles:
	@cd src && opp_makemake --make-so $(MAKEMAKE_OPTIONS)
	@cd simulations && opp_makemake $(MAKEMAKE_OPTIONS)

checkmakefiles:
	@if [ ! -f src/Makefile -o ! -f simulations/Makefile ]; then \
	echo; \
	echo ' ---------------------------------------------------------'; \
	echo '| Makefiles in "src/" and/or "simulations/" do not exist. |'; \
	echo '|      Please use "make makefiles" to generate them!      |'; \
	echo ' ---------------------------------------------------------'; \
	echo; \
	exit 1; \
	fi
